package com.bappi.utils;

import com.post799.soundapp.R;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class AlertUtils {
	public interface OnButtonClickListener {
		public void onClick(View v, Dialog dialog);
	}

	public static final void showCustomAlert(Context context, String message,
			String title, String leftButtonText, String rightButtonText,
			final OnButtonClickListener leftButtonListener,
			final OnButtonClickListener rightButtonListener,
			int leftBackground, int rightBackground) {
		try {
			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.message_dialog_two_buttons);
			dialog.setCancelable(false);
			TextView titleView = (TextView) dialog
					.findViewById(R.id.title_view);
			titleView.setText(title);
			TextView textView = (TextView) dialog.findViewById(R.id.text_view);
			textView.setText(message);

			// set up button
			Button leftButton = (Button) dialog.findViewById(R.id.button_left);

			leftButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(leftButtonListener!=null){
						leftButtonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			leftButton.setText(leftButtonText);
			leftButton.setBackgroundResource(leftBackground);

			Button rightButton = (Button) dialog
					.findViewById(R.id.button_right);
			rightButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(rightButtonListener!=null){
						rightButtonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			rightButton.setText(rightButtonText);
			rightButton.setBackgroundResource(rightBackground);
			// now that the dialog is set up, it's time to show it
			dialog.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static final void showCustomAlert(Context context, String message,
			String title, String leftButtonText, String rightButtonText,
			final OnButtonClickListener leftButtonListener,
			final OnButtonClickListener rightButtonListener) {
		try {
			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.message_dialog_two_buttons);
			dialog.setCancelable(false);
			TextView titleView = (TextView) dialog
					.findViewById(R.id.title_view);
			titleView.setText(title);
			TextView textView = (TextView) dialog.findViewById(R.id.text_view);
			textView.setText(message);
			// set up button
			Button leftButton = (Button) dialog.findViewById(R.id.button_left);
			leftButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(leftButtonListener!=null){
						leftButtonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			leftButton.setText(leftButtonText);
			Button rightButton = (Button) dialog
					.findViewById(R.id.button_right);
			rightButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(rightButtonListener!=null){
						rightButtonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			rightButton.setText(rightButtonText);
			// now that the dialog is set up, it's time to show it
			dialog.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static final void showCustomAlert(Context context, String message,
			String title, String buttonText,
			final OnButtonClickListener buttonListener, int buttonBackground) {
		try {
			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.message_dialog_one_button);
			dialog.setCancelable(false);
			TextView titleView = (TextView) dialog
					.findViewById(R.id.title_view);
			titleView.setText(title);
			TextView textView = (TextView) dialog.findViewById(R.id.text_view);
			textView.setText(message);

			// set up button
			Button button = (Button) dialog.findViewById(R.id.button);
			button.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if (buttonListener != null) {
						buttonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			button.setText(buttonText);
			button.setBackgroundResource(buttonBackground);

			// now that the dialog is set up, it's time to show it
			dialog.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static final void showCustomAlert(Context context, String message,
			String title, String buttonText,
			final OnButtonClickListener buttonListener) {
		try {
			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.message_dialog_one_button);
			dialog.setCancelable(false);
			TextView titleView = (TextView) dialog
					.findViewById(R.id.title_view);
			titleView.setText(title);
			TextView textView = (TextView) dialog.findViewById(R.id.text_view);
			textView.setText(message);

			// set up button
			Button button = (Button) dialog.findViewById(R.id.button);
			button.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if (buttonListener != null) {
						buttonListener.onClick(v, dialog);
					}else{
						dialog.dismiss();
					}
				}
			});
			button.setText(buttonText);
			// now that the dialog is set up, it's time to show it
			dialog.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
